#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/4/25 16:27
# @File    : t3.py
# @Description : -i http://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn




import sys
import time
import threading
from tk_dev.buy6.thread_check import MyThread


def my_test_func(num):
    for i in range(num):
        time.sleep(.1)
        print(f"threadName:{threading.current_thread().getName()}, ThreadID:{threading.current_thread().native_id}, item:{i}")
        if i==9:
            raise RuntimeError(123)

def func_main():
    #pool = ThreadPoolExecutor(max_workers=3, thread_name_prefix='')
    batch = 20
    target = 90
    task_pool = [MyThread(target=my_test_func, name=f"task-{n}", args=(10,)) for n in range(batch)]
    [t.start() for t in task_pool]

    finish = batch
    while finish <= target-1:
        for _, t in enumerate(task_pool):
            if not t.is_alive():
                # print(f"task-{finish}")
                task_pool[_] = MyThread(target=my_test_func, name=f"task-{finish}", args=(10,))
                task_pool[_].start()
                finish += 1
            #time.sleep(1)




master = MyThread(target=func_main, name="master")
master.start()
start = time.time()
master.join()

print("------------")

print(time.time()-start)
#input()
